package com.lhb.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.10.11 下午 20:15
 */

@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha() {
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        //1.边框
        properties.setProperty("kaptcha.border", "no");
        //2.生成验证码的位数
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        //3.验证码的范围
        properties.setProperty("kaptcha.textproducer.char.string", "1234567890abcdefgkh");
        //4.验证码的颜色
        properties.setProperty("kaptcha.background.clear.to", "211,229,237");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;

    }
}
